package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.CglibUtil;
import com.ruoyi.system.domain.vo.WhCompanyVo;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.WhCompanyMapper;
import com.ruoyi.system.domain.WhCompany;
import com.ruoyi.system.service.IWhCompanyService;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;

/**
 * 公司配置Service业务层处理
 * @author ruoyi
 * @date 2023-02-25
 */
@Service
public class WhCompanyServiceImpl implements IWhCompanyService {

    @Resource
    private WhCompanyMapper whCompanyMapper;

    /**
     * 查询公司配置
     *
     * @param id 公司配置主键
     * @return 公司配置
     */
    @Override
    public WhCompany selectWhCompanyById(Integer id) {
        return whCompanyMapper.selectWhCompanyById(id);
    }

    /**
     * 查询公司配置列表
     *
     * @param whCompany 公司配置
     * @return 公司配置
     */
    @Override
    public List<WhCompany> selectWhCompanyList(WhCompany whCompany) {
        return whCompanyMapper.selectWhCompanyList(whCompany);
    }

    /**
     * 客户端获取公司列表
     * @return
     */
    @Override
    public List<WhCompanyVo> findCompanyList() {
        WhCompany whCompany = new WhCompany();
        whCompany.setIsDelete(1);
        whCompany.setStatus(1);
        List<WhCompany> whCompanies = whCompanyMapper.selectWhCompanyList(whCompany);
        List<WhCompanyVo> list = new ArrayList<>();
        if (!CollectionUtils.isEmpty(whCompanies)) {
            list = CglibUtil.copyList(whCompanies,WhCompanyVo::new);
        }
        return list;
    }

    /**
     * 新增公司配置
     *
     * @param whCompany 公司配置
     * @return 结果
     */
    @Override
    public int insertWhCompany(WhCompany whCompany) {
        whCompany.setCreateTime(DateUtils.getNowDate());
        whCompany.setIsDelete(1);
        return whCompanyMapper.insertWhCompany(whCompany);
    }

    /**
     * 修改公司配置
     *
     * @param whCompany 公司配置
     * @return 结果
     */
    @Override
    public int updateWhCompany(WhCompany whCompany) {
        whCompany.setUpdateTime(DateUtils.getNowDate());
        return whCompanyMapper.updateWhCompany(whCompany);
    }

    /**
     * 批量删除公司配置
     *
     * @param ids 需要删除的公司配置主键
     * @return 结果
     */
    @Override
    public int deleteWhCompanyByIds(Integer[] ids) {
        return whCompanyMapper.deleteWhCompanyByIds(ids);
    }

    /**
     * 删除公司配置信息
     *
     * @param id 公司配置主键
     * @return 结果
     */
    @Override
    public int deleteWhCompanyById(Integer id) {
        return whCompanyMapper.deleteWhCompanyById(id);
    }
}
